//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.th.common.mybatis.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;

import com.th.common.domain.UsUser;
import com.th.common.mybatis.query.LambdaQueryWrapperX;
import com.th.common.mybatis.util.MyBatisUtils;
import com.th.common.response.PageParam;
import com.th.common.response.PageResult;
import com.th.common.vo.RegisterUserVo;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 配置
 * @author tuhang
 */
public interface BaseMapperX<T> extends BaseMapper<T> {
    default T InsertOne(String username,String password){
        return null;
    }
    /**
     * 默认分页功能
     * @param pageParam
     * @param queryWrapper
     * @return
     */
    default PageResult<T> selectPage(PageParam pageParam, @Param("ew") Wrapper<T> queryWrapper) {
        IPage<T> mpPage = MyBatisUtils.buildPage(pageParam);
        this.selectPage(mpPage, queryWrapper);
        return new PageResult(mpPage.getRecords(), mpPage.getTotal());
    }

    /**
     * 查询某个对象
     * @param field
     * @param value
     * @return
     */
    default T selectOne(String field, Object value) {
        return (T) this.selectOne((Wrapper) (new QueryWrapper()).eq(field, value));
    }

    /**
     * LambdaQueryWrapperX 查询某个对象
     * @param column
     * @param val
     * @return
     */
    default T selectOne(SFunction<T, ?> column, Object val) {
        return (T) this.selectOne((new LambdaQueryWrapperX()).eq(column, val));
    }

    /**
     * LambdaQueryWrapperX 查询某个对象
     * @param column
     * @param val
     * @return
     */
    default List<T> selectList(SFunction<T, ?> column, Object val) {
        return (List<T>) this.selectList((new LambdaQueryWrapperX()).eq(column, val));
    }


    /**
     * 查询某个对象
     * @param field
     * @param value
     * @return
     */
    default Long selectCount(String field, Object value) {
        return this.selectCount((Wrapper)(new QueryWrapper()).eq(field, value));
    }

    /**
     * 查询某个对象
     * @param column
     * @param value
     * @return
     */
    default Long selectCount(SFunction<T, ?> column, Object value) {
        return this.selectCount((Wrapper)(new LambdaQueryWrapperX()).eq(column, value));
    }


    default Integer insertOne(UsUser registerUserVo){
        return this.insert((T) registerUserVo);
    }


}
